import 'package:common/common.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../global_web/global_web_page.dart';
import '../../model/login_config_model.dart';

class AgreementWidget extends StatelessWidget {
  const AgreementWidget({super.key, this.isChecked = false, required this.onChecked, required this.config});

  final LoginConfig config;

  final bool isChecked;
  final Function onChecked;

  @override
  Widget build(BuildContext context) {
    Links link1 = config.links!.first;
    Links link2 = config.links!.last;
    return Container(
      margin: const EdgeInsets.symmetric(vertical: 22),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 2),
            child: Image.asset(
                    isChecked ? 'assets/app/images/auth/auth_check_s.png' : 'assets/app/images/auth/auth_check_n.png',
                    width: 15.0.w)
                .onTap(() {
              onChecked.call();
            }),
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.only(left: 10, right: 10),
              child: RichText(
                  maxLines: 3,
                  text: TextSpan(children: [
                    TextSpan(text: "已阅读并同意", style: TextStyle(color: const Color(0xFF999999), fontSize: 12.sp)),
                    TextSpan(
                        text: ' ${link1.title}',
                        style: TextStyle(color: const Color(0xFF25D4D0), fontSize: 12.sp),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            GlobalWebPage.startInstance(link1.title ?? '', link1.click!.jump ?? '');
                          }),
                    TextSpan(text: "和", style: TextStyle(color: const Color(0xFF999999), fontSize: 12.sp)),
                    TextSpan(
                        text: ' ${link2.title}',
                        style: TextStyle(color: const Color(0xFF25D4D0), fontSize: 12.sp),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            GlobalWebPage.startInstance(link2.title ?? '', link2.click!.jump ?? '');
                          }),
                    TextSpan(
                        text: "并使用本机号码登录，首次登录将自动注册", style: TextStyle(color: const Color(0xFF999999), fontSize: 12.sp)),
                  ])),
            ),
          ),
        ],
      ),
    );
  }
}
